part of 'isar.dart';

mixin LocalDataRelaxInfo {
  List<RelaxInfo> relaxs = List.empty(growable: true);

  queryRelaxInfo() async {
    relaxs = await isar.relaxInfos.where().sortByDateDesc().findAll() ?? [];
    print('relax:${relaxs.length}');
  }
}

extension ExtDataRelaxInfo on List<RelaxInfo> {
  save(RelaxInfo relaxInfo) {
    isar.write((isar) async {
      isar.relaxInfos.put(relaxInfo);
    });
  }

  Future<bool> isExist(String date) async {
    int count = await isar.relaxInfos.where().dateEqualTo(date).count();
    return count > 0;
  }

  delete(String date) {
    isar.write((isar) async {
      isar.relaxInfos.where().dateEqualTo(date).deleteAll();
    });
  }
}
